import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: () => import('../views/Manage.vue'),
    redirect:"/home",
    children: [
      {path: 'home', name: '首页', component: () => import('../views/Home.vue')},
      {path: 'admin', name: '管理员管理', component: () => import('../views/Admin.vue')},
      {path: 'landlord', name: '房东管理', component: () => import('../views/Landlord.vue')},
      {path: 'tenant', name: '租户管理', component: () => import('../views/Tenant.vue')},
      {path: 'renter', name: '店铺求租管理', component: () => import('../views/Renter.vue')},
      {path: 'shop', name: '店铺出租管理', component: () => import('../views/Shop.vue')},
      {path: 'contract', name: '合同管理', component: () => import('../views/Contract.vue')}
    
    ]
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next)=>{
  localStorage.setItem("currentPathName",to.name)//设置当前路由名称
  store.commit("setPath")
  next()
})

export default router
